<?php

namespace App\Model;

use PhalApi\Model\DataModel;

class CutDownTimes extends DataModel
{
    public $tableName = 'phalapi_user';
    protected function getTableName($id)
    {
        return $this->tableName;
    }
    //减少, 单位的使用次数
    public function cutDown($unit)
    {
        if ( $unit ){
            //查出单位的负责人帐号
            $where = array(
                "unit" => $unit,
                "is_admin" => 'admin'
            );
            $userInfo = $this->getORM()->select('id,used_times')->where($where)->fetchOne();
            //如果有信息,就返回相关数组
            if ($userInfo) {
                $this->getORM()->where('id', $userInfo['id'] )->update(array('used_times' => $userInfo['used_times']-1));
            }
        }
    }
}
